package cn.edu.pku.controller;

import cn.edu.pku.entity.BookCategory;
import cn.edu.pku.service.BookCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 图书分类controller
 * Created by intelligentdroid on 2017/5/9.
 */
@RestController
@RequestMapping(value = "/book/category")
@Slf4j
public class BookCategoryController {

    @Autowired
    BookCategoryService service;

    @RequestMapping(value = "/getall",method = {RequestMethod.GET,RequestMethod.POST})
    public List<BookCategory> getAllCategory(){
        return service.getAllCategory();
    }

    @RequestMapping(value = "/add")
    public int addBookCategory(@RequestParam(name = "name",required = true) String bookcategoryName){
        return service.addBookCategory(bookcategoryName);
    }

    @RequestMapping(value = "/delete")
    public int deleteBookCategoryByid(@RequestParam(name = "id") int id){
        return service.deleteBookCategory(id);
    }

    @RequestMapping(value = "/update")
    public int updateBookCategory(@RequestParam(name = "id") int id,@RequestParam(name = "name") String name){
        return service.updateBookCategory(id,name);
    }
    @RequestMapping(value = "/search")
    public List<BookCategory> getCategoryByName(@RequestParam(name = "name") String name){
        return service.getCategoryByName(name);
    }
}
